package com.nt.mapreduce020201_hello.yarn.weather01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Weather01Job {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //加载配置文件
        Configuration configuration = new Configuration(true);
        //本地模式运行
        configuration.set("mapreduce.framework.name", "local");
        //创建Job
        Job job = Job.getInstance(configuration);
        //设置Job的信息
        job.setJarByClass(Weather01Job.class);
        job.setJobName("Weather01-" + System.currentTimeMillis());
        job.setNumReduceTasks(2);

        //设置数据的读取路径
        FileInputFormat.setInputPaths(job, new Path("/lzj/area_weather.txt"));
        //设置结果的输出路径
        FileOutputFormat.setOutputPath(job, new Path("/lzj/result/" + job.getJobName()));

        //设置Map的输出数据格式----Reduce的输入格式
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        //设置Map的处理类
        job.setMapperClass(Weather01Mapper.class);
        //设置Reduce的处理类
        job.setReducerClass(Weather01Reducer.class);

        //提交任务等待完成
        job.waitForCompletion(true);
    }

}
